home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Code_Fragments / LoadList.c < prev    next >
C/C++ Source or Header  |  1998-09-18  |  1KB  |  58 lines

  1.  
  2. /* 
  3.     LoadList.c - Loads/writes an ASCII List to/from an Att_List
  4.          
  5. */
  6.  
  7. #include <proto/dos.h>
  8. #include <proto/exec.h>
  9.  
  10. #define _DOPUS_MODULE_DEF
  11. #include <dopus/modules.h>
  12.  
  13. #define SDI_TO_ANSI
  14. #include <sdi_std.h>
  15.  
  16. /********************************************************************/
  17.  
  18. Att_List *LoadList( STRPTR filename )
  19. {
  20.           BPTR file;
  21.           char buffer[256];
  22.           Att_List *list = NULL;
  23.           
  24.           if( (file = Open(filename, MODE_OLDFILE)) )
  25.             {
  26.                list = Att_NewList( LISTF_POOL );
  27.                          
  28.                while( FGets(file, buffer, 256) )
  29.                  {
  30.                     buffer[strlen(buffer)-1] = 0x00;
  31.                     Att_NewNode( list, buffer, NULL, NULL );
  32.                  }
  33.                                           
  34.                Close( file );                          
  35.                
  36.             }
  37.      return list;
  38. }
  39.  
  40. /********************************************************************/
  41.  
  42. void WriteList( Att_List *entrylist, STRPTR header )
  43. {
  44.           BPTR file;
  45.           ULONG count = 0;
  46.           STRPTR out;
  47.           
  48.           file = Open( TEMP_FILE, MODE_NEWFILE );
  49.           
  50.           if( header )
  51.                FPuts( file, header );
  52.           
  53.           while( (out = Att_NodeName(entrylist, count++)) )
  54.                FPuts( file, out );
  55.           
  56.           Close( file );
  57. }
  58.